package com.yqw.spring1219.concert;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 观众
 * @author abc
 *
 */
@Aspect
public class Audience {
	
	/**
	 * 定义命名的切点
	 */
	@Pointcut("execution(* com.yqw.spring1219.concert.Performance.perform(..))")
	public void performce() {}
	
	/**
	 * 将手机调至静音状态
	 */
	@Before("performce()")
	public void silenceCellPhones() {
		System.out.println("Silencing cell phones");
	}
	
	/**
	 * 就座
	 */
	@Before("performce()")
	public void takeSeats() {
		System.out.println("Taking seats");
	}
	
	/**
	 * 鼓掌喝彩
	 */
	@AfterReturning("performce()")
	public void applauce() {
		System.out.println("CLAP CLAP CLAP!");
	}

	/**
	 * 要求退款
	 */
	@AfterThrowing("performce()")
	public void demanedRefund() {
		System.out.println("Demaned a refund");
	}
	
	@Around("performce()")
	public void watchPerformance(ProceedingJoinPoint jp){
		try {
			System.out.println("Silencing cell phones");
			System.out.println("Taking seats");
			jp.proceed();
			System.out.println("CLAP CLAP CLAP!");
		} catch (Throwable e) {
			System.out.println("Demaned a refund");
		}
	}
}
